<!DOCTYPE html>
<html>
<head>
  <title>JoinQuery.java</title>
  <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'/>
  <link rel='stylesheet' type='text/css' href='../../../../../coverage.css'/>
  <link rel='shortcut icon' type='image/png' href='../../../../../logo.png'/>
  <script type='text/javascript' src='../../../../../coverage.js'></script>
  <script type='text/javascript' src='../../../../../prettify.js'></script>
</head>
<body onload='prettyPrint()'>
  <table cellpadding='0' cellspacing='1'>
    <caption>igraph_client_java/src/main/java/com/taobao/igraph/client/model/JoinQuery.java</caption>
    <tr>
      <td class='line'>1</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>package com.taobao.igraph.client.core.model;</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'></td><td>&nbsp;</td>
      <td><pre class='imports prettyprint' onclick='showHideLines(this)'><div>import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;

import lombok.NonNull;

import com.taobao.igraph.client.common.IGraphClientException;
</div><span>import ...</span></pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>11</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>public class JoinQuery extends PGQuery {</pre></td>
    </tr>
    <tr>
      <td class='line'>12</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    private PGQuery leftQuery;</pre></td>
    </tr>
    <tr>
      <td class='line'>13</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    private AtomicQuery rightQuery;</pre></td>
    </tr>
    <tr>
      <td class='line'>14</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    private String joinfield;</pre></td>
    </tr>
    <tr>
      <td class='line'>15</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    private Map&lt;String, String> kvPairs;</pre></td>
    </tr>
    <tr>
      <td class='line'>16</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    private String filter;</pre></td>
    </tr>
    <tr>
      <td class='line'>17</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    private String sorter;</pre></td>
    </tr>
    <tr>
      <td class='line'>18</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    private String distinct;</pre></td>
    </tr>
    <tr>
      <td class='line'>19</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    private String orderby;</pre></td>
    </tr>
    <tr>
      <td class='line'>20</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    private String[] fields;</pre></td>
    </tr>
    <tr>
      <td class='line'>21</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    private int start;</pre></td>
    </tr>
    <tr>
      <td class='line'>22</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    private int count;</pre></td>
    </tr>
    <tr>
      <td class='line'>23</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    private boolean isRangeValid;</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'></td><td>&nbsp;</td>
      <td class='comment' onclick='showHideLines(this)'><div>    /**
     * @param joinField
     *            指定关联字段，该字段必须在leftQuery返回的MatchRecord中存在， 用于生成rightQuery中的keys参数列表
     *            ,如果指定了sorter参数，那么MergeSearch会对merge之后的结果进行排序，这里使用用户定制的排序模块。
     * @return
     */</div><span>    /*...*/</span></td>
    </tr>
    <tr>
      <td class='line'>31</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public JoinQuery(@NonNull PGQuery leftQuery, @NonNull AtomicQuery rightQuery, @NonNull String joinField) {</pre></td>
    </tr>
    <tr>
      <td class='line'>32</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        if (!rightQuery.isJoinQueryOnly()) {</pre></td>
    </tr>
    <tr>
      <td class='line'>33</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            throw new IGraphClientException("the right AtomicQuery of JoinQuery should not contain KeyList");</pre></td>
    </tr>
    <tr>
      <td class='line'>34</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr>
      <td class='line'>35</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        this.leftQuery = leftQuery;</pre></td>
    </tr>
    <tr>
      <td class='line'>36</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        this.rightQuery = rightQuery;</pre></td>
    </tr>
    <tr>
      <td class='line'>37</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        this.joinfield = joinField;</pre></td>
    </tr>
    <tr>
      <td class='line'>38</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        kvPairs = new LinkedHashMap&lt;String, String>();</pre></td>
    </tr>
    <tr>
      <td class='line'>39</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        this.isRangeValid = false;</pre></td>
    </tr>
    <tr>
      <td class='line'>40</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>42</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public JoinQuery setSorter(@NonNull String sorter) {</pre></td>
    </tr>
    <tr>
      <td class='line'>43</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        this.sorter = sorter;</pre></td>
    </tr>
    <tr>
      <td class='line'>44</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        return this;</pre></td>
    </tr>
    <tr>
      <td class='line'>45</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>47</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public JoinQuery setDistinct(@NonNull String distinct) {</pre></td>
    </tr>
    <tr>
      <td class='line'>48</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        this.distinct = distinct;</pre></td>
    </tr>
    <tr>
      <td class='line'>49</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        return this;</pre></td>
    </tr>
    <tr>
      <td class='line'>50</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>52</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public JoinQuery setOrderby(@NonNull String orderby) {</pre></td>
    </tr>
    <tr>
      <td class='line'>53</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        this.orderby = orderby;</pre></td>
    </tr>
    <tr>
      <td class='line'>54</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        return this;</pre></td>
    </tr>
    <tr>
      <td class='line'>55</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>57</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public JoinQuery setFilter(@NonNull String filter) {</pre></td>
    </tr>
    <tr>
      <td class='line'>58</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        this.filter = filter;</pre></td>
    </tr>
    <tr>
      <td class='line'>59</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        return this;</pre></td>
    </tr>
    <tr>
      <td class='line'>60</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>62</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public JoinQuery setRange(int start, int count) {</pre></td>
    </tr>
    <tr>
      <td class='line'>63</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        if (start &lt; 0 || count &lt; 0) {</pre></td>
    </tr>
    <tr>
      <td class='line'>64</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            throw new IGraphClientException("negative start or count is not allowed, start=[" + start + "], count=["</pre></td>
    </tr>
    <tr>
      <td class='line'>65</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                    + count + "] is not valid!");</pre></td>
    </tr>
    <tr>
      <td class='line'>66</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr>
      <td class='line'>67</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        this.start = start;</pre></td>
    </tr>
    <tr>
      <td class='line'>68</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        this.count = count;</pre></td>
    </tr>
    <tr>
      <td class='line'>69</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        this.isRangeValid = true;</pre></td>
    </tr>
    <tr>
      <td class='line'>70</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        return this;</pre></td>
    </tr>
    <tr>
      <td class='line'>71</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>73</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public JoinQuery setReturnFields(@NonNull String... fields) {</pre></td>
    </tr>
    <tr>
      <td class='line'>74</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        if (fields.length == 0) {</pre></td>
    </tr>
    <tr>
      <td class='line'>75</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            throw new IGraphClientException("empty returnFields is not allowed!");</pre></td>
    </tr>
    <tr>
      <td class='line'>76</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr>
      <td class='line'>77</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        this.fields = fields;</pre></td>
    </tr>
    <tr>
      <td class='line'>78</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        return this;</pre></td>
    </tr>
    <tr>
      <td class='line'>79</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'></td><td>&nbsp;</td>
      <td class='comment' onclick='showHideLines(this)'><div>    /**
     * @Deprecated use {@link #addKvPair} instead
     */</div><span>    /*...*/</span></td>
    </tr>
    <tr>
      <td class='line'>84</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    @Deprecated</pre></td>
    </tr>
    <tr>
      <td class='line'>85</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public JoinQuery addKvpair(@NonNull String key, @NonNull String value) {</pre></td>
    </tr>
    <tr>
      <td class='line'>86</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        return addKvPair(key, value);</pre></td>
    </tr>
    <tr>
      <td class='line'>87</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>89</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public JoinQuery addKvPair(@NonNull String key, @NonNull String value) {</pre></td>
    </tr>
    <tr>
      <td class='line'>90</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        kvPairs.put(key, value);</pre></td>
    </tr>
    <tr>
      <td class='line'>91</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        return this;</pre></td>
    </tr>
    <tr>
      <td class='line'>92</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>94</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public JoinQuery setKvPairs(@NonNull Map&lt;String, String> kvPairs) {</pre></td>
    </tr>
    <tr>
      <td class='line'>95</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        this.kvPairs = kvPairs;</pre></td>
    </tr>
    <tr>
      <td class='line'>96</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        return this;</pre></td>
    </tr>
    <tr>
      <td class='line'>97</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>99</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public String toString() {</pre></td>
    </tr>
    <tr>
      <td class='line'>100</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        String left = leftQuery.toString();</pre></td>
    </tr>
    <tr>
      <td class='line'>101</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        String right = rightQuery.toString();</pre></td>
    </tr>
    <tr>
      <td class='line'>102</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        StringBuilder ss = new StringBuilder(left.length() + right.length() + 128);</pre></td>
    </tr>
    <tr>
      <td class='line'>103</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        ss.append('(').append(left);</pre></td>
    </tr>
    <tr>
      <td class='line'>104</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        join(ss);</pre></td>
    </tr>
    <tr>
      <td class='line'>105</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        ss.append(right).append(')');</pre></td>
    </tr>
    <tr>
      <td class='line'>106</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        return ss.toString();</pre></td>
    </tr>
    <tr>
      <td class='line'>107</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>109</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    private void join(StringBuilder ss) {</pre></td>
    </tr>
    <tr>
      <td class='line'>110</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        ss.append("join{").append("joinfield=").append(joinfield);</pre></td>
    </tr>
    <tr>
      <td class='line'>111</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        if (filter != null) {</pre></td>
    </tr>
    <tr>
      <td class='line'>112</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            ss.append("&filter=").append(filter);</pre></td>
    </tr>
    <tr>
      <td class='line'>113</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr>
      <td class='line'>114</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        if (sorter != null) {</pre></td>
    </tr>
    <tr>
      <td class='line'>115</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            ss.append("&sorter=").append(sorter);</pre></td>
    </tr>
    <tr>
      <td class='line'>116</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr>
      <td class='line'>117</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        if (distinct != null) {</pre></td>
    </tr>
    <tr>
      <td class='line'>118</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            ss.append("&distinct=").append(distinct);</pre></td>
    </tr>
    <tr>
      <td class='line'>119</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr>
      <td class='line'>120</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        if (orderby != null) {</pre></td>
    </tr>
    <tr>
      <td class='line'>121</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            ss.append("&orderby=").append(orderby);</pre></td>
    </tr>
    <tr>
      <td class='line'>122</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr>
      <td class='line'>123</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        if (isRangeValid) {</pre></td>
    </tr>
    <tr>
      <td class='line'>124</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            ss.append("&range=").append(start).append(':').append(count);</pre></td>
    </tr>
    <tr>
      <td class='line'>125</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr>
      <td class='line'>126</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        if (!kvPairs.isEmpty()) {</pre></td>
    </tr>
    <tr>
      <td class='line'>127</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            ss.append("&kvpairs=");</pre></td>
    </tr>
    <tr>
      <td class='line'>128</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            boolean first = true;</pre></td>
    </tr>
    <tr>
      <td class='line'>129</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            for (Entry&lt;String, String> entry : kvPairs.entrySet()) {</pre></td>
    </tr>
    <tr>
      <td class='line'>130</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                if (!first) {</pre></td>
    </tr>
    <tr>
      <td class='line'>131</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                    ss.append(";");</pre></td>
    </tr>
    <tr>
      <td class='line'>132</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                }</pre></td>
    </tr>
    <tr>
      <td class='line'>133</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                first = false;</pre></td>
    </tr>
    <tr>
      <td class='line'>134</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                ss.append(entry.getKey());</pre></td>
    </tr>
    <tr>
      <td class='line'>135</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                ss.append(":");</pre></td>
    </tr>
    <tr>
      <td class='line'>136</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                ss.append(entry.getValue());</pre></td>
    </tr>
    <tr>
      <td class='line'>137</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            }</pre></td>
    </tr>
    <tr>
      <td class='line'>138</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr>
      <td class='line'>139</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        if (fields != null && fields.length > 0) {</pre></td>
    </tr>
    <tr>
      <td class='line'>140</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            ss.append("&fields=");</pre></td>
    </tr>
    <tr>
      <td class='line'>141</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            boolean first = true;</pre></td>
    </tr>
    <tr>
      <td class='line'>142</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            for (String field : fields) {</pre></td>
    </tr>
    <tr>
      <td class='line'>143</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                if (!first) {</pre></td>
    </tr>
    <tr>
      <td class='line'>144</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                    ss.append(";");</pre></td>
    </tr>
    <tr>
      <td class='line'>145</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                }</pre></td>
    </tr>
    <tr>
      <td class='line'>146</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                first = false;</pre></td>
    </tr>
    <tr>
      <td class='line'>147</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                ss.append(field);</pre></td>
    </tr>
    <tr>
      <td class='line'>148</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            }</pre></td>
    </tr>
    <tr>
      <td class='line'>149</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr>
      <td class='line'>150</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        ss.append('}');</pre></td>
    </tr>
    <tr>
      <td class='line'>151</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr>
      <td class='line'>152</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>}</pre></td>
    </tr>
  </table>
</body>
</html>
